TOP

SQL INNER JOIN

SQL INNER JOIN Description

The INNER keyword JOIN selects records that have matching values ​​in both tables.


SQL INNER JOIN Syntax

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name

SQL INNER JOIN

Demonstration database

Below is a sample from the table "Orders" ("Orders"):

ProductIDOrderIDCustomerIDEmployeeIDOrderDateShipperID
1102489051996-07-043
2102498161996-07-051
3102503441996-07-082

And the selection from the table "Customers" ("Customers"):

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.5021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.5023Mexico

SQL INNER JOIN Example

The following SQL statement selects all orders with customer information:

Run SQLSELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID
The INNER keyword JOIN selects all rows from both tables if there is a match between the columns. If there are records in table "Orders" ("Orders") that do not match in "Customers" ("Customers"), those orders will not be displayed!

SQL INNER JOIN to join three tables

The following SQL statement selects all orders with customer and shipper information:

Run SQLSELECT Orders.OrderID, Customers.CustomerName, Shippers.ShipperName 
FROM ((Orders INNER JOIN Customers 
       ON Orders.CustomerID = Customers.CustomerID) 
       
      INNER JOIN Shippers 
      ON Orders.ShipperID = Shippers.ShipperID)